home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 9 / The PC-SIG Library on CD ROM - Ninth Edition.iso / 1501_600 / DISK1533 / DISK1533.ZIP / SIZEOF.C < prev    next >
Text File  |  1989-02-22  |  2KB  |  104 lines

  1. /*
  2.  * SIZEOF.C - utility program will return the total filesize of named argument
  3.  *
  4.  * Usage: sizeof: c ==> count total matches and summarize
  5.  *          i ==> list individual files if wildcard used
  6.  *          q ==> quiet mode, use for counting only
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <dir.h>
  12.  
  13. static char * Program [] = { "sizeof - s. leoce",
  14.                  "V1 R0 SVCLVL 1 @ " };
  15.  
  16. int main( int, char * [] );    /* main function decl */
  17.  
  18. static char * pfmterr = "usage: sizeof [-ciq] file [[-iq] file ... ]\n";
  19. static char * popterr = "sizeof: illegal option";
  20. static char * pnofile = "sizeof: no such file";
  21.  
  22. #define    FALSE    0
  23. #define    TRUE    1
  24.  
  25. int main(argc, argv)
  26. int argc;
  27. char * argv[];
  28. {
  29.  
  30.     register long total = 0;
  31.     auto short int LineOption = 0;
  32.     auto short int count = FALSE;
  33.     auto short int indiv = FALSE;
  34.     auto short int verbose = TRUE;
  35.     auto int final  = 0, files = 0;
  36.     auto char * file;    /* file name begin checked */
  37.  
  38.     if( argc < 2 )
  39.         _exit( fprintf( stderr, "%s\n", pfmterr ) + 0x04 );
  40.  
  41.     while( --argc > 0 ) {
  42.         ++argv;        /* show first arg */
  43.         if( ( LineOption = **argv ) == '-' || LineOption == '/')
  44.             while( LineOption = *(++(*argv)) ) {    /* switch */
  45.                 switch( LineOption ) {
  46.                 case 'c':
  47.                     count = TRUE;
  48.                     break;
  49.                 case 'i':
  50.                     indiv = TRUE;
  51.                     break;
  52.                 case 'q':
  53.                     verbose = FALSE;
  54.                     break;
  55.                 default:
  56.                     fprintf(stderr,"%s %c\n", popterr,
  57.                          LineOption);
  58.                 }
  59.             }
  60.         else {  /* try to process files, or nothing */
  61.             auto found = FALSE;
  62.  
  63.             if( ! ( file = _wild( *argv ) ) ) {
  64.                 fprintf( stderr, "%s %s\n", pnofile,
  65.                     strupr( *argv ) );
  66.                 found = FALSE;
  67.             }
  68.             else do {    /* hit all files */
  69.                 auto struct ffblk ffblk;
  70.  
  71.                 findfirst( file, &ffblk, 0 );
  72.                 total += ffblk.ff_fsize;
  73.                 if( indiv )
  74.                     fprintf( stdout, "%-25s %10ld\n",
  75.                         strupr(file), ffblk.ff_fsize);
  76.                 final++;
  77.                 files++;
  78.                 found = TRUE;
  79.  
  80.             } while( file = _wild( NULL ) );
  81.  
  82.             if( found && verbose )
  83.                 if( ! indiv ) {
  84.                     fprintf(stdout, "%-25s %10ld",
  85.                         strupr(*argv), total);
  86.                     if( _FAttr & WILDCARDS )
  87.                         fprintf(stdout,", %d",files);
  88.                     putchar( '\n' );
  89.                 }
  90.                 else
  91.                     fprintf( stdout, "%25s %10ld, %d (%s)\n",
  92.                     "Total:",total,files,strupr(*argv));
  93.  
  94.             indiv = FALSE;
  95.             verbose = TRUE;
  96.             total = 0L;
  97.             files = 0;
  98.         }
  99.     }
  100.  
  101.     if( count && final )
  102.         fprintf( stdout, "\n\t%d files\n", final );
  103. }
  104.